import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:meal/components/market/recommend_activity.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 推荐活动
///
class RecommendActivity extends StatefulWidget {
  const RecommendActivity({Key? key}) : super(key: key);

  @override
  State<RecommendActivity> createState() => _RecommendActivityState();
}

class _RecommendActivityState extends State<RecommendActivity> with SingleTickerProviderStateMixin {
  late TabController _controller;

  List<String> tabs = ['全部活动', '进行中'];

  PreferredSizeWidget get bottom {
    return PreferredSize(
        preferredSize: const Size.fromHeight(Sizes.default50),
        child: Container(
          decoration: const BoxDecoration(
            color: Colors.white,
          ),
          height: Sizes.default50,
          alignment: Alignment.center,
          child: ToolsUtils.getClientTabBar(tabs, _controller),
        ));
  }

  @override
  void initState() {
    _controller = TabController(length: tabs.length, vsync: this);
    super.initState();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ToolsUtils.getDefaultBackgroundColor(),
      appBar: ToolsUtils.getDefaultBrnAppBar('商品推荐活动', bottom: bottom),
      body: TabBarView(
        controller: _controller,
        children: const [MarketRecommendActivity(), MarketRecommendActivity(isAll: false)],
      ),
      bottomNavigationBar: SafeArea(
        top: false,
        child: Container(
          height: Sizes.default50,
          alignment: Alignment.center,
          child: TextButton(
              onPressed: () {
                Get.toNamed(RouteGet.marketRecommendAdd);
              },
              child: Text(
                '创建活动 2/5',
                style: StylesUtils.customTextStyle(
                    fontSize: Sizes.default15, color: ColorsUtils.color797),
              )),
        ),
      ),
    );
  }
}
